<?php

/*
 *   showMap.php
 *
 *   Embarrasingly messy code to display the map.
 * 
 *
 *
 * LICENSE:
 *
 *   Copyright 2005 Matt Kubilus
 *
 *   This file is part of crimemap.
 *
 *   Crimemap is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   Crimemap is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Crimemap; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


//	include 'dbconnect.php';
//	include 'activity.php';

	function setSQL($s)
	{
		$sql = $s;
	}

	setSQL("SELECT * FROM crimemap_activity");
	
	
?>



    <script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAA8ZOlRYjf9r6w95uNvvw0khSGVT6R9T0N9RKkACEZKikgRg_w1xSa00EzxwY86Xo5EgUr5ybUNDxbDA" type="text/javascript"></script>



    <div id="map" style="width: 500px; height: 600px"></div>
    <script type="text/javascript">
    //<![CDATA[
    
    var map = new GMap(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.centerAndZoom(
    new GPoint('-85.330675', '34.996902'), 2);

	function createMarker(point, message) {
	  var marker = new GMarker(point);

	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(message);
	  });

	  return marker;
	}
    

    <?php 

	$db = new dbConnection();
	$db->connect();
	$act = new activity($db);
	$db->execute("SELECT address, longitude, latitude, CAST(description AS CHAR(32)) AS description, datetime FROM crimemap_activity LIMIT 0, 20");
	$result = $db->getResults();
	$num = $db->getNumRows();	

	$i=0;
	while ($i < $num) 
	{

		$address=mysql_result($result,$i,"address");
		$description=mysql_result($result, $i, "description");
		$datetime=mysql_result($result, $i, "datetime");
		
		//$loc = $act->geocode($address);

		$latitude = mysql_result($result, $i, "latitude");
		$longitude = mysql_result($result, $i, "longitude");

		$i++;
		
    ?>
	    
    var point = 
    new GPoint(<?php echo $longitude;?>, <?php echo $latitude;?>);
    var marker =  createMarker(point, "<?php echo $address ?> <?php echo "<p>"; echo $description; echo "<p>"; echo $datetime ?>");
    map.addOverlay(marker);
    
    <?php

	    }  //End while
		$db->disconnect();
    ?>

    //]]>
    </script>


